@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <h5>活动列表</h5>
        </div>
        <div class="ibox-content">
            <form method="post" id="formInsert" class="form-horizontal" onsubmit="return false">
                <div class="form-group"><label class="col-sm-2 control-label">标题</label>
                    <div class="col-sm-8"><input type="text" class="form-control" name="title" placeholder="请输入标题" required="" value="{{$row->title}}"></div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">活动分类</label>
                    <div class="col-sm-2">
                        <select class="form-control " name="class_id" required>
                            <option>---请选择分类----</option>
                            @foreach($class as $v)
                                <option value="{{$v->id}}" @if($row->class_id==$v->id) selected @endif>{{$v->name}}</option>
                            @endforeach
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">活动</label>
                    <div class="col-sm-2">
                        <select class="form-control " name="activity_id" required>
                            <option>---请选择活动----</option>
                            @foreach($activity as $v)
                                <option value="{{$v->id}}" @if($row->activity_id==$v->id) selected @endif>{{$v->title}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">开始时间</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" placeholder="请输入标题" id="datetime" name="start_time" value="{{$row->start_time}}" required>
                    </div>
                    <!-- <label class="col-sm-2 control-label">结束时间</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" placeholder="请输入标题" id="datetimeEnd" name="end_time" value="{{$row->end_time}}" required>
                    </div> -->
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group "><label class="col-sm-2 control-label">上传图片</label>
                    <div class="col-sm-8">
                        <input type="file" class="form-control" name="pic" >
                        @if($row->pic1)
                            <img src="{{asset($row->pic)}}">
                        @endif
                        
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <input type="hidden" class="form-control" name="id" value="{{$row->id}}">
                        <button class="btn btn-primary" type="submit">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

@endsection

@section('pageheader')

@endsection
@section('pagescript')
    <script src="/assets/layDate/laydate.js"></script>
<!--     <script src="/assets/ueditor/ueditor.config.js"></script>
    <script src="/assets/ueditor/ueditor.all.js"></script> -->
<script>
    $("#side-menu li[rel='activity']").addClass("active")
    .find("ul").addClass("in")
    .find("li[rel='2']").addClass("active");
        
    var filter = {page:1,status:0};
    var ueditor;
    laydate.render({
        elem: '#datetime'
        ,type: 'datetime'
    });
    $(function () {
        
        // ueditor = UE.getEditor('ueditor_content', {zIndex: 9});
        // ueditor.ready(function() {//编辑器初始化完成再赋值
        //     ueditor.setContent("{{$row->content}}",false);  //赋值给UEditor
        // });


        $("body").on("submit", "#formInsert", function(){
            var form = document.getElementById("formInsert");
            var formData = new FormData(form);
            $.ajax({
                url:"/admin/banner/store",
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                success:function(data){
                    layer.msg('操作成功');
                    if("{{$row->id}}"){
                        window.history.go(-1);
                    }else{
                        $('#formInsert')[0].reset();
                    }
                    ueditor.execCommand('cleardoc');
                },
                error:function(data){
                      var str = typeof(data) == 'string' ? data : data.responseJSON;
                      layer.msg(str, {icon:0});
                      return false;
                }
            });

            return false;
        });
    })

</script>
@endsection
